package com.hdd.hll.quartz.config;

import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * 调度器配置
 */
@Configuration
public class ScheduleConfig {

    public static final String PROP_SCHED_INSTANCE_NAME = "org.quartz.scheduler.instanceName";
    public static final String PROP_SCHED_INSTANCE_ID = "org.quartz.scheduler.instanceId";
    public static final String PROP_SCHED_THREAD_POOL_COUNT = "org.quartz.threadPool.threadCount";
    public static final String INSTANCE_NAME = "京东推送任务";
    public static final String INSTANCE_ID = "JD_JOB";
    public static final String THREAD_POOL_COUNT = "17";

    @Bean(name = "scheduler")
    public Scheduler getScheduler() throws SchedulerException {
        StdSchedulerFactory stf = new StdSchedulerFactory();
        Properties jobProp = new Properties();
        jobProp.setProperty(PROP_SCHED_INSTANCE_NAME, INSTANCE_NAME);
        jobProp.setProperty(PROP_SCHED_INSTANCE_ID, INSTANCE_ID);
        jobProp.setProperty(PROP_SCHED_THREAD_POOL_COUNT, THREAD_POOL_COUNT);
        stf.initialize(jobProp);
        return stf.getScheduler();
    }

}
